<?php

namespace App\Http\Controllers\Admin;

use App\Http\Filters\HousingsLesseeFilter;
use App\Models\HousingsLessee;
use App\Http\Requests\HousingsLesseeRequest;
use App\Http\Resources\HousingsLesseeResource;
use Illuminate\Http\Request;

class HousingsLesseeController extends Controller
{
    public function index(HousingsLesseeFilter $filter)
    {
        $housingsLessees = HousingsLessee::query()
            ->filter($filter)
            ->paginate();

        return $this->ok(HousingsLesseeResource::collection($housingsLessees));
    }

    public function create()
    {
        return $this->ok();
    }

    public function store(HousingsLesseeRequest $request)
    {
        $inputs = $request->validated();
        $housingsLessee = HousingsLessee::create($inputs);

        return $this->created(HousingsLesseeResource::make($housingsLessee));
    }

    public function edit(Request $request, HousingsLessee $housingsLessee)
    {
        return $this->ok(HousingsLesseeResource::make($housingsLessee));
    }

    public function update(HousingsLesseeRequest $request, HousingsLessee $housingsLessee)
    {
        $inputs = $request->validated();
        $housingsLessee->update($inputs);

        return $this->created(HousingsLesseeResource::make($housingsLessee));
    }

    public function destroy(HousingsLessee $housingsLessee)
    {
        $housingsLessee->delete();
        return $this->noContent();
    }
}
